import type { IDraggable, IShapeType } from "./types";

/* 由于可能存在大量创建对象的情况，用class更容易初始化 */
export class Draggable implements IDraggable {
  declare x: number;
  declare y: number;
  declare w: number;
  declare h: number;
  declare rotate: number;
  declare originX: number;
  declare originY: number;
  declare minWidth: number;
  declare minHeight: number;
  declare maxWidth: number;
  declare maxHeight: number;
  declare parent?: boolean;
  declare zoom: number;
  declare draggable?: boolean | undefined;
  declare rotatable?: boolean | undefined;
  /* 拖拽步长[x,y,z] */
  declare gap: number[];
  declare resizable?: boolean | undefined;
  declare z?: number | undefined;
  declare id?: string | undefined;
  declare disabled?: boolean | undefined;
  declare preventDeactivation?: boolean | undefined;
  declare snap: number;
  declare overflow: boolean;
  declare lockAspectRatio: boolean;
  declare scale: number;
  declare skewX: number;
  declare skewY: number;

  declare borderColor: string;
  declare className?: string;
  declare type: IShapeType;
  declare grid: number[];
  constructor(config?: Partial<IDraggable>) {
    const defaultValue: IDraggable = {
      x: 0,
      y: 0,
      w: 0,
      h: 0,
      rotate: 0,
      originX: 0,
      originY: 0,
      minWidth: -Infinity,
      minHeight: -Infinity,
      maxWidth: Infinity,
      maxHeight: Infinity,
      parent: false,
      grid: [1, 1, 90],
      draggable: true,
      rotatable: true,
      resizable: true,
      disabled: false,
      preventDeactivation: true,
      overflow: false,
      lockAspectRatio: false,
      className: "",
      borderColor: "",
      type: "rect",
      show: true
    };
    Object.assign(this, defaultValue, config);
  }
  axis?: "x" | "y" | "both" | undefined;
  declare show: boolean;
}
